package com.gm.server.voice.core.runable;
import com.gm.server.voice.core.UserInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.Queue;

/**
 * 接收音频并播放
 */
public class ReceiveAudio implements Runnable{

    private String roomId;
    private String userId;
    private Socket socket;

    byte[] buffer = new byte[1024];

    private Queue<UserInputStream> userInputStreamQueue;

    public ReceiveAudio(String roomId, String userId,Socket socket) {
        this.roomId = roomId;
        this.userId = userId;
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            while (true) {
                // 获取输入流
                InputStream in = socket.getInputStream();
                if (in == null) {
                    continue;
                }
                // 存放于输出队列
                UserInputStream userInputStream = new UserInputStream(roomId, userId, in);
                userInputStreamQueue.add(userInputStream);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
